package com.youhui.weixin.controller;

import com.youhui.weixin.common.exception.LoadFileException;
import com.youhui.weixin.domain.Goods;
import com.youhui.weixin.domain.Types;
import com.youhui.weixin.service.ExcelRedisService;
import com.youhui.weixin.service.GoodsService;
import com.youhui.weixin.service.TypesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * Created by https://github.com/kuangcp on 17-10-9  下午6:22
 * 主要的路由
 */
@Controller
public class BaseController {

    @Autowired
    private GoodsService goodsService;
    @Autowired
    private TypesService typesService;

    /**
     * 跳转首页.
     * @param model
     * @return
     */
    @RequestMapping("/index")
    public String index(Model model) {
        Page<Goods> hotGoods = goodsService.getHotGoods(0);
        model.addAttribute("hotGoods", hotGoods);
        List<Types> types = typesService.getHomeTypes();
        model.addAttribute("types", types);
        List<Types> allTypes = typesService.getAllTypes();
        model.addAttribute("allTypes", allTypes);
        return "index";
    }

    @RequestMapping("/help")
    public String help(){
        return "help";
    }

    @RequestMapping("/nothavegood")
    public String error(){
        return "error";
    }
    /**
     * 分类跳转.
     * @param typeId 分类编号
     * @param model
     * @return
     */
    @RequestMapping("/type/{typeId}")
    public String toTypePage(@PathVariable("typeId") int typeId, Model model) {
        Types type = typesService.getTypeById(typeId);
        Page<Goods> goods = goodsService.getTypeGoods(typeId, 0);
        List<Types> types = typesService.getAllTypes();
        model.addAttribute("types", types);
        model.addAttribute("goods", goods);
        model.addAttribute("type", type);
        return "cloths";
    }

    /**
     * 跳转商品详细页面.
     * @param goodId 商品编号
     * @param model model
     * @return
     */
    @RequestMapping("/good/{goodId}")
    public String Detail(@PathVariable("goodId") long goodId, Model model) {
        Goods goods = goodsService.getGoodsById(goodId);
        model.addAttribute("goods", goods);
        return "Details";
    }

    @RequestMapping("/type")
    public String type(){
        return "type";
    }

    @RequestMapping("/cloths")
    public String cloths(){
        return "cloths";
    }
    @RequestMapping("/classification")
    public String classification(){
        return "classification";
    }
    @RequestMapping("/Details")
    public String details(){
        return "Details";
    }

    @RequestMapping("/searchs")
    public String search() {
        return "search";
    }

    @RequestMapping("/feedback")
    public String feedback() {
        return "feedback";
    }


}
